﻿using ThomasGIS.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ThomasGIS.Projections
{
    public class BD09 : ITransform
    {
        public void Toward(Point point)
        {
            double PI = 3.141592653589793 * 3000.0 / 180.0;
            double x = point.X;
            double y = point.Y;
            double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * PI);
            double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * PI);

            point.X = z * Math.Cos(theta) + 0.0065;
            point.Y = z * Math.Sin(theta) + 0.006;
        }

        public void Backward(Point point)
        {
            double PI = 3.141592653589793 * 3000.0 / 180.0;
            double x = point.X - 0.0065;
            double y = point.Y - 0.006;
            double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * PI);
            double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * PI);

            point.X = z * Math.Cos(theta);
            point.Y = z * Math.Sin(theta);
        }
    }
}
